package com.panda.mall.user.exception;

/**
 * author: tcy
 * createDate: 2022/10/9
 * description:
 */
import com.panda.mall.common.result.Result;
import com.panda.mall.common.result.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ControllerAdvice
public class ServiceExceptionAdvice {

    public static Logger logger = LoggerFactory.getLogger(ServiceExceptionAdvice.class);

    @ResponseBody
    @ExceptionHandler({ServiceException.class})
    public Result execute(ServiceException e){
        logger.error("业务异常",e);
        Result resultVo = new Result();
        resultVo.setCode(e.getCode());
        resultVo.setMessage(e.getMessage());
        return resultVo;
    }
}
